package com.qianfeng.zhangwei.extras.acitivity;

import android.content.Intent;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.qianfeng.zhangwei.extras.BaseApplication;
import com.qianfeng.zhangwei.extras.R;
import com.qianfeng.zhangwei.extras.eventbus.EventBusActivity_;
import com.qianfeng.zhangwei.extras.recycler.RecyclerActivity_;
import com.qianfeng.zhangwei.extras.utils.AppManager;

import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;


@EActivity(R.layout.activity_main)
public class MainActivity extends BaseActivity {
    public static final String URLTHREADGET = "http://mob.feimaor.com/jiabijia.action?fid=promotionstart&imei=6973b893e15bae3cfab12d86460d5f04%3B867633020918082&udid=ec0709678c493a99f8ea86e042531cff%3B38%3Abc%3A1a%3A49%3A3c%3A0c&phone=&simopt=&model=m1+note&appversion=3550000&os=android&osversion=4.4.4&screen=1080*1920&chkey=and&net=0";


    @ViewById(R.id.main_listview)
    ListView listView;

    private ArrayList<String> list = new ArrayList<>();

    @Override
    public void inject() {
        list.add("线程通信框架");
        list.add("环信");
        list.add("RecyclerView");
    }

    @Override
    public void initView() {
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, list);
        listView.setAdapter(arrayAdapter);
    }


    @Override
    public void initData() {
        HttpUtils httpUtils = new HttpUtils();
        httpUtils.send(HttpRequest.HttpMethod.GET, URLTHREADGET, new RequestCallBack<String>() {

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                Log.e("test", responseInfo.result);
            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @ItemClick(R.id.main_listview)
    public void onItemClick(int position) {
        switch (position) {
            case 0:
                startActivity(new Intent(this, EventBusActivity_.class));
                break;
            case 1:
                break;
            case 2:
                startActivity(new Intent(this, RecyclerActivity_.class));
                break;
        }
    }


    @Override
    public void onBackPressed() {
        AppManager.getAppManager().AppExit(BaseApplication.getInstance());
    }
}
